package com.weigee.ktv.presenter.adapter.rv

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.LinearLayout
import com.linde.library.adapter.BaseRvAdapter
import com.linde.library.adapter.SimpleViewHolder
import com.linde.library.util.DisplayUtil
import com.linde.library.util.DisplayUtil.Companion.dip2px
import com.weigee.ktv.R
import com.weigee.ktv.R.id.iv_divider
import kotlinx.android.synthetic.main.adapter_notification.view.*

/**
 * Created by linde on 2017/6/1.
 *<p/>
 */
class NotificationAdapter : BaseRvAdapter<String>() {
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): SimpleViewHolder {
        val view = LayoutInflater.from(parent?.context).inflate(R.layout.adapter_notification, parent, false)
        return SimpleViewHolder(view)
    }

    override fun onBindViewHolder(holder: SimpleViewHolder?, position: Int) {
        super.onBindViewHolder(holder, position)
        holder ?: return
        val v = holder.itemView

        if (position == itemCount - 1) {
            try {
                val layoutParams = v.iv_divider.layoutParams as LinearLayout.LayoutParams
                layoutParams.leftMargin = DisplayUtil.dip2px(v.context, 0F)
                layoutParams.rightMargin = DisplayUtil.dip2px(v.context, 0F)
                v.iv_divider.layoutParams = layoutParams
            } catch(e: Exception) {
                e.printStackTrace()
            }
        }
        v.setOnClickListener {
        }
    }

    override fun getItemCount(): Int {
//   todo     return super.getItemCount()
        return 22
    }
}